//
//  DealCell.m
//  小团购
//
//  Created by 樊荣海 on 15/1/30.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "DealCell.h"

@implementation DealCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setDealModel:(DealModel *)dealModel {

    _dealModel = dealModel;
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:_dealModel.image_url] placeholderImage:[UIImage imageNamed:@"placeholder_deal"]];
    self.desc.text = _dealModel.desc;
    self.price.text = _dealModel.current_price_text;
    [self.purchaseCount setTitle:[NSString stringWithFormat:@"%d",_dealModel.purchase_count] forState:UIControlStateNormal];
    
    
    // 5.标签
    // 5.1.获得当前时间字符串
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSString *now = [fmt stringFromDate:[NSDate date]];
    
    // 5.2.比较当前时间
    NSString *icon = nil;
    if ([dealModel.publish_date isEqualToString:now]) {
        icon = @"ic_deal_new.png";
    } else if ([dealModel.purchase_deadline isEqualToString:now]) {
        icon = @"ic_deal_soonOver.png";
    } else if ([dealModel.purchase_deadline compare:now] == NSOrderedAscending) {
        icon = @"ic_deal_over.png";
    }
    
    _badge.hidden = icon == nil;
    _badge.image = [UIImage imageNamed:icon];

    
}

@end
